<?php
namespace Admin\Controller;



class ProjectReviewController extends AbstractController  {
	
	protected $From;

	public function _initialize(){
		$this->assign("busid",I("busid"));
		$this->assign("formid",I("formid"));
		$this->Form = D('Projectreview');
    }
	
    public function index(){
    	$id = (int)I('id');
    	$this->assign("projectID",$id);
    	$res = $this->Form->MyshowList();
		$this->assign("list",$res['list']);
    	$this->assign("page",$res['page']);
    	$this->display("Project/ProjectReview/index");
    }
	
	public function save($type = false){
		if($type != false){
			if($type == "add"){
				if(!$this->Form->create()){
					exit($this->error($this->Form->getError()));
				}else{
					$result = $this->Form->add();
					if($result){
						$ExpertID = I('ExpertID');
						if(!empty($ExpertID)){
							$Expert = M("projectreview_expert_rel");
							$data['PRID'] = $result;
                        	$data['ExpertID'] = $ExpertID;				
							$resid = $Expert->add($data);
							if($resid){
								$this->success('添加成功！');
							}else{
								$this->error('项目评审专家关联错误！');
							}
						}else{
							$this->success('添加成功！');
						}
					}else{
						$this->error('评审添加错误！');
					}
				}
			}else if($type == "edit"){
				if(I('id')){
					$res = $this->Form->Myshow(array("ID" => (int)I('id')));
					$this->assign("editdata",$res[0]);
					$res = $this->Form->getProjectList();
					$this->assign("Projectdata",$res);
					$res = $this->Form->getExpertList();
					$this->assign("Expertdata",$res);
				}
				$this->display("Project/ProjectReview/save");
			}if($type == "update"){
					$result = $this->Form->Myupdata();
					$ExpertID = I('ExpertID');
					$expertformid = I('expertformid');
					$ID = I('ID');
					if(!empty($ExpertID)){
						$Expert = M("projectreview_expert_rel");
						$data['PRID'] = $ID;
                       	$data['ExpertID'] = $ExpertID;
						$resid = $Expert->where($expertformid)->save($data);
						$this->success($result['msg']);
						/*
						if(!empty($resid)){
							$this->success($result['msg']);
						}else{
							$this->error('项目评审专家关联错误！');
						}
						*/
					}else{
						$this->success($result['msg']);
					}
			}
		}else{
			$res = $this->Form->getProjectList();
			$this->assign("Projectdata",$res);
			$res = $this->Form->getExpertList();
			$this->assign("Expertdata",$res);
			$this->display("Project/ProjectReview/save");
		}
	}
}